package com.euond.permission.entities;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.euond.common.core.entities.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * Created by Daniel on 13/06/2017.
 * system menu class
 */
@Setter
@Getter
@TableName("sys_menu")
public class Menu extends BaseEntity {

    /**
     * 租赁公司ID
     */
    private Long companyId;

    /**
     * 项目ID
     */
    private Long projectId;

    /**
     * 排序号
     */
    @NotNull
    private Integer sequence;

    /**
     * 菜单名称
     */
    @Size(min = 4, max = 32)
    @NotNull
    private String name;

    /**
     * 菜单图标
     */
    @Size(min = 1, max = 64)
    @NotNull
    private String icon;

    /**
     * 资源ID
     * 当值为0时,表示主菜单,为非0时则必须存在于资源列表中
     */
    @NotNull
    private Long resourceId;

    /**
     * 资源名称
     */
    @TableField(exist = false)
    private String resourceName;

    /**
     * 是否菜单
     */
    @TableField(exist = false)
    private Integer ifMenu;

    /**
     * 父ID
     */
    @NotNull
    private Long parentId;

    /**
     * 父路径
     */
    @Size(min = 1, max = 32)
    @NotNull
    private String parentIds;

    /**
     * 状态
     */
    @NotNull
    private Integer status;


    /**
     * 资源对象(有了它导致menu对象无法转换成json，所以需要去掉)
     */
    //@TableField(exist = false)
   // private Resource resource;

    /**
     * 资源的URL
     */
    @TableField(exist = false)
    private String url;

    /**
     * 是子菜单吗?
     *
     * @return boolean
     */
    public boolean isSubMenu() {
        return resourceId != 0;
    }

    /**
     * 获取Url
     *
     * @return
     */
   // public String getUrl() {
   //     return isSubMenu() ? resource.getUrl() : "";
   // }
}